﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using SuggestionEngine.AirportSVC;

namespace SuggestionEngine
{
    /*
    public class AirportServiceCallback : IAirportServiceCallback
    {
        private ISuggestionEngineService _suggestionEngineSvc;

        public AirportServiceCallback()
            : this(new SuggestionEngineService())
        {
        }

        public AirportServiceCallback(ISuggestionEngineService suggestionEngineSvc)
        {
            _suggestionEngineSvc = suggestionEngineSvc;
        }

        

    }
    */

    public class SuggestionEngineService : IAirportServiceCallback, ISuggestionEngineService
    {
        private InstanceContext _site;
        // Service references
        private IAirportService _airportSvcClient;
        private IAirportServiceCallback _callbackHandler;

        // Airport environment data members
        private List<Flight> _flightList = new List<Flight>();
        private Map _airportMap;

        public SuggestionEngineService()
        {
            //_site = new InstanceContext(new AirportServiceCallback(this));
            _site = new InstanceContext(this);
            _airportSvcClient = new AirportServiceClient(_site, "NetTcpBinding_IAirportService");

            // Register with Airport Service to receive updates when new Flights are added
            _airportSvcClient.RegisterForFlightUpdates();
        }

        public SuggestionEngineService(IAirportService airportSvcClient)
        {
            //_site = new InstanceContext(airportServiceCallback);
            _site = new InstanceContext(this);
            _airportSvcClient = airportSvcClient;

            // Register with Airport Service to receive updates when new Flights are added
            _airportSvcClient.RegisterForFlightUpdates();
        }

        public List<Flight> FlightList
        {
            get
            {
                return _flightList;
            }

            set
            {
                _flightList = value;
            }
        }

        public Map AirportMap
        {
            get
            {
                return _airportMap;
            }

            set
            {
                _airportMap = value;
            }
        }

        public Route GetShortestPath(Plane plane, Node start, Node end)
        {
            return null;
        }

        public void newFlightUpdate(Flight newFlight)
        {
            FlightList.Add(newFlight);
        }

        // Notifies all listeners that a plane position has changed
        public void PlanePositionUpdate(int planeId, Node newLocation)
        {
        }

        public void IncomingAirportLayout(Map airportMap)
        {
        }

    }
}
